

package com.maoshi.shop.groupbuy.multishop.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.maoshi.shop.common.annotation.SysLog;
import com.maoshi.shop.common.util.PageParam;
import com.maoshi.shop.groupbuy.comment.model.GroupOrder;
import com.maoshi.shop.groupbuy.comment.service.GroupOrderService;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author LGH
 * @date 2019-08-27 17:55:57
 */
@RestController
@AllArgsConstructor
@RequestMapping("/group/order")
public class GroupOrderController {

    private final GroupOrderService groupOrderService;

    /**
     * 分页查询
     *
     * @param page       分页对象
     * @param groupOrder
     * @return 分页数据
     */
    @GetMapping("/page")
    public ResponseEntity<IPage<GroupOrder>> getGroupOrderPage(PageParam<GroupOrder> page, GroupOrder groupOrder) {

        return ResponseEntity.ok(groupOrderService.page(page, new LambdaQueryWrapper<GroupOrder>()));
    }


    /**
     * 通过id查询
     *
     * @param groupOrderId id
     * @return 单个数据
     */
    @GetMapping("/info/{groupOrderId}")
    public ResponseEntity<GroupOrder> getById(@PathVariable("groupOrderId") Long groupOrderId) {
        return ResponseEntity.ok(groupOrderService.getById(groupOrderId));
    }

    /**
     * 新增
     *
     * @param groupOrder
     * @return 是否新增成功
     */
    @SysLog("新增")
    @PostMapping
    public ResponseEntity<Boolean> save(@RequestBody @Valid GroupOrder groupOrder) {
        return ResponseEntity.ok(groupOrderService.save(groupOrder));
    }

    /**
     * 修改
     *
     * @param groupOrder
     * @return 是否修改成功
     */
    @SysLog("修改")
    @PutMapping
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid GroupOrder groupOrder) {
        return ResponseEntity.ok(groupOrderService.updateById(groupOrder));
    }

    /**
     * 通过id删除
     *
     * @param groupOrderId id
     * @return 是否删除成功
     */
    @SysLog("删除")
    @DeleteMapping("/{groupOrderId}")
    public ResponseEntity<Boolean> removeById(@PathVariable Long groupOrderId) {
        return ResponseEntity.ok(groupOrderService.removeById(groupOrderId));
    }

}
